package com.ukao.cashregister.adapter;

import android.content.Context;
import android.content.res.Resources;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mcxtzhang.commonadapter.rv.CommonAdapter;
import com.mcxtzhang.commonadapter.rv.ViewHolder;
import com.ukao.cashregister.R;
import com.ukao.cashregister.bean.Coupons;
import com.ukao.cashregister.utils.CheckUtils;
import com.ukao.cashregister.utils.MyDateUtils;

import java.util.List;

/**
 * 优惠券
 */

public class CouponsAdapter extends CommonAdapter<Coupons> {

    private   boolean    isPayEnter;

    public CouponsAdapter(Context context, List<Coupons> datas) {
        super(context, datas, R.layout.coupons_items);

    }
    public void   setisPayEnter(Boolean  isPayEnter){
        this.isPayEnter=isPayEnter;
    }


    @Override
    public void convert(ViewHolder viewHolder, Coupons coupons) {
        Resources mResources = mContext.getResources();
        TextView  credits=viewHolder.getView(R.id.coupons_credits_tv);
        TextView availableCondition= viewHolder.getView(R.id.coupons_available_condition_tv);
        TextView  name=viewHolder.getView(R.id.coupons_name_tv);
        TextView   type=viewHolder.getView(R.id.coupons_type_tv);
        TextView   validDate= viewHolder.getView(R.id.coupons_valid_date_tv);
        LinearLayout iamgeBackgroud=viewHolder.getView(R.id.iamge_backgroud);
        ImageView iamgePastdue=viewHolder.getView(R.id.iamge_pastdue);
        TextView   mouey= viewHolder.getView(R.id.mouey);
        ImageView   paySelect= viewHolder.getView(R.id.pay_select);



        validDate.setText(MyDateUtils.formatDate(coupons.getTimeStart())+"至"+MyDateUtils.formatDate(coupons.getTimeEnd()));/*时间*/
        type. setText(CheckUtils.isEmptyString(coupons.getCouponRuleName()));
        name.setText(coupons.getName());/*标题*/
        availableCondition.setText(coupons.fullAmount == 0 ? "无限制" : "满" + CheckUtils.isEmptyNumber(coupons.getFullAmount()) + "可使用");
        credits.setText(CheckUtils.isEmptyNumber(coupons.getAmount()));

        if (isPayEnter){     /*金额用不了*/
            viewHolder.itemView.setEnabled(coupons.getEnableUse());

            if (coupons.getEnableUse()||coupons.isCheck()){/*是否可用*/
                viewHolder.itemView.setAlpha(1f);
                credits.setTextColor(mResources.getColor(R.color.orange));
                mouey.setTextColor(mResources.getColor(R.color.orange));
                availableCondition .setTextColor(mResources.getColor(R.color.black_gray));
                name.setTextColor(mResources.getColor(R.color.black));
                type. setTextColor(mResources.getColor(R.color.black_gray));
                validDate.setTextColor(mResources.getColor(R.color.black_gray));//coupons_valid_date
                iamgeBackgroud.setBackgroundResource(R.drawable.coupons_valid);
                iamgePastdue.setVisibility(View.GONE);
                paySelect.setVisibility(coupons.isCheck() ? View.VISIBLE : View.GONE);
            }else{
//                mouey.setTextColor(mResources.getColor(R.color.dilog_past));
//                validDate.setTextColor(mResources.getColor(R.color.dilog_past));
//                type. setTextColor(mResources.getColor(R.color.dilog_past));
//                name.setTextColor(mResources.getColor(R.color.dilog_past));
//                availableCondition .setTextColor(mResources.getColor(R.color.dilog_past));
//                credits.setTextColor(mResources.getColor(R.color.dilog_past));
//                iamgeBackgroud.setBackgroundResource(R.drawable.coupons_un_valid);
                viewHolder.itemView.setAlpha(0.5f);
                paySelect.setVisibility(View.GONE);
            }

        }




}}
